home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / src / libgplus.5 / libgplus / etc / lf / dirent.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-29  |  1.9 KB  |  108 lines

  1. /* Define a portable UNIX directory-entry manipulation interface. 
  2.  
  3.    This code is heavily based upon Doug Gwyn's public domain directory-access
  4.    routines written in C.  Hacked into C++ conformance for the GNU libg++
  5.    library by Douglas C. Schmidt (schmidt@ics.uci.edu). */
  6.  
  7. #include <std.h>
  8. #include "Dirent.h"
  9.  
  10. // error handlers
  11.  
  12. void verbose_Dirent_error_handler(const char* msg)
  13. {
  14.   perror(msg);
  15.   errno = 0;
  16. }
  17.  
  18. void quiet_Dirent_error_handler(const char*)
  19. {
  20.   errno = 0;
  21. }
  22.  
  23. void fatal_Dirent_error_handler(const char* msg)
  24. {
  25.   perror(msg);
  26.   exit(1);
  27. }
  28.  
  29. one_arg_error_handler_t Dirent_error_handler = verbose_Dirent_error_handler;
  30.  
  31.  
  32. one_arg_error_handler_t set_Dirent_error_handler(one_arg_error_handler_t f)
  33. {
  34.   one_arg_error_handler_t old = Dirent_error_handler;
  35.   Dirent_error_handler = f;
  36.   return old;
  37. }
  38.  
  39. #ifndef __OPTIMIZE__
  40.  
  41. /* Initialize the directory-entry control block from the given DIRNAME.
  42.    Equivalent to opendir (). */
  43.  
  44. Dirent::Dirent (char *dirname) 
  45. {
  46.   if ((dirp = ::opendir (dirname)) == 0)
  47.     (*Dirent_error_handler) ("Dirent::Dirent");
  48. }
  49.  
  50. /* Frees up the dynamically allocated buffer. */
  51.  
  52. Dirent::~Dirent (void)
  53. {
  54.   ::closedir (dirp);
  55. }
  56.  
  57. /* Re-initialize the directory-entry control block from the given DIRNAME.
  58.    Equivalent to opendir (). */
  59.  
  60. void
  61. Dirent::opendir (char *dirname) 
  62. {
  63.   if ((dirp = ::opendir (dirname)) == 0)
  64.     (*Dirent_error_handler) ("Dirent::Dirent");
  65. }
  66.  
  67. /* Read next entry from a directory stream. */
  68.  
  69. struct dirent *
  70. Dirent::readdir (void)
  71. {
  72.   return ::readdir (dirp);
  73. }
  74.  
  75. /* Close a directory stream. */
  76.  
  77. void
  78. Dirent::closedir (void)
  79. {
  80.   ::closedir (dirp);
  81. }
  82.  
  83. /* Rewind a directory stream. */
  84.  
  85. void
  86. Dirent::rewinddir (void)
  87. {
  88.   ::seekdir (dirp, long (0));
  89. }
  90.  
  91. /* Reposition a directory stream. */
  92.  
  93. void
  94. Dirent::seekdir (long loc)
  95. {
  96.   ::seekdir (dirp, loc);
  97. }
  98.  
  99. /* Report directory stream position. */
  100.  
  101. long
  102. Dirent::telldir (void)
  103. {
  104.   return ::telldir (dirp);
  105. }
  106.  
  107. #endif // __OPTIMIZE__
  108.